#include <stdio.h>
#include <string.h>
#include <sys/select.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/select.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>

#define MAX_LEN 64

int fd;

void process_func(int signo)
{
	char buf[MAX_LEN] = {0};
	int len;

	printf("signo: %d \n", signo);
	len = read(fd, buf, sizeof(buf));
	buf[len] = '\0';
	printf("read: %s, size: %d \n", buf, len);
	return;
}

int main(int argc, char **argv)
{
	int flag;

	//open
	fd = open("/dev/hello_dev", O_RDWR);
	if(fd < 0) {
		perror("open error \n");
		return 0;
	}
	printf("open success \n");

	fcntl(fd, F_SETOWN, getpid());
	flag = fcntl(fd, F_GETFL);
	fcntl(fd, F_SETFL, flag | FASYNC);
	signal(SIGIO, process_func);  // receipt signal

	while(1);

	close(fd);

	return 0;
}
